package cn.caskm.souvenirshopsystem.controller.api;

import cn.caskm.souvenirshopsystem.domain.Result;
import cn.caskm.souvenirshopsystem.domain.dto.PageDTO;
import cn.caskm.souvenirshopsystem.domain.query.SeckillGoodsQuery;
import cn.caskm.souvenirshopsystem.domain.vo.SeckillGoodsVO;
import cn.caskm.souvenirshopsystem.service.SeckillGoodsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/seckill")
@RequiredArgsConstructor
public class SeckillController {

    private final SeckillGoodsService seckillGoodsService;

    @GetMapping("/ongoing")
    public Result<List<SeckillGoodsVO>> getOngoingSeckillGoods() {
        return seckillGoodsService.getOngoingSeckillGoods();
    }

    @GetMapping("/upcoming")
    public Result<List<SeckillGoodsVO>> getUpcomingSeckillGoods() {
        return seckillGoodsService.getUpcomingSeckillGoods();
    }

    @GetMapping("/detail/{seckillId}")
    public Result<SeckillGoodsVO> getSeckillGoodsDetail(@PathVariable("seckillId") Integer seckillId) {
        return seckillGoodsService.getSeckillGoodsDetail(seckillId);
    }

    @GetMapping("/page")
    public Result<PageDTO<SeckillGoodsVO>> page(SeckillGoodsQuery query) {
        // 前台只显示进行中和即将开始的秒杀
        if (query.getSeckillStatus() == null) {
            query.setSeckillStatus("1"); // 默认只显示进行中的
        }
        return seckillGoodsService.page(query);
    }

}
